package com.github.shiqiyue.blog.markdown.controller;

import javax.servlet.http.HttpSession;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.WebAttributes;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.github.shiqiyue.blog.markdown.controller.base.BaseController;

/***
 * 登录控制器
 * 
 * @author wwy
 *
 */
@Controller
@RequestMapping("/login")
public class LoginController extends BaseController {
	
	@RequestMapping
	public String loginPage(HttpSession httpSession, String username, Model model) {
		// 获取认证失败的exception
		AuthenticationException exception = (AuthenticationException) httpSession
				.getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
		if (exception != null) {
			model.addAttribute("loginError", exception.getMessage());
			httpSession.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
		}
		model.addAttribute("username", username);
		return "login";
	}
	
}
